$(function () {
/*    var history=LsyStorage.getItem('localHistory');
    history=history?history:[];*/
    $('#history').on('click','a',function(e){
        e.preventDefault();
        var search=$(this).text();
        window.location.href = './proList.html?searchInfo=' + search;
    });
    $('#submit').tap(function () {
        var search = $('#search').val();
        var history=checkHistory(search,4);
        LsyStorage.setItem('localHistory',history);
        window.location.href = './proList.html?searchInfo=' + search;

    });
    makeHistoryOut();
    function checkHistory(res,num){
        var historyDatas=LsyStorage.getItem('localHistory');
        historyDatas=historyDatas?historyDatas:[];
        for(var j=0,len=historyDatas.length;j<len;j++) {
            if(res==historyDatas[j]){
                historyDatas.splice($.inArray(res,historyDatas),1);
            }
        }
        historyDatas.unshift(res);
        if(historyDatas.length>num){
            historyDatas.pop();
        }
        return historyDatas;
    }
    function makeHistoryOut(){
        var historyDatas=LsyStorage.getItem('localHistory');
        historyDatas=historyDatas?historyDatas:[];
        var str='';
        for(var j=0,len=historyDatas.length;j<len;j++){
            str+='<a href="">'+historyDatas[j]+'</a>'
        }
        $('#historyText').html(str);
    }
    $('#clear').tap(function () {
        var historyDatas=LsyStorage.getItem('localHistory');
        historyDatas=historyDatas?historyDatas:[];
        historyDatas.splice(0);
        console.log(historyDatas);
        var history=LsyStorage.getItem('localHistory');
        var str='';
        for(var j=0,len=historyDatas.length;j<len;j++){
            str+='<a href="">'+historyDatas[j]+'</a>'
        }
        $('#historyText').html(str);
        LsyStorage.removeItem('localHistory');

    })
});